package doh.util;

import java.io.FileInputStream;
import java.util.Properties;

public class SystemProperties {
    Properties dohProp;

    public SystemProperties() {
        try {
            dohProp = new Properties();
            FileInputStream in = new FileInputStream(get_dir_path() + "/doh.config.properties");
            dohProp.load(in);
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public String get_class_name() {
        String class_name;
        class_name = this.getClass().getName();
        class_name = class_name.substring(class_name.lastIndexOf(".") + 1,class_name.length());
        class_name += ".class";
        return class_name;
   }

    public String get_dir_path() {
        String dir_name;
        java.net.URL myURL = this.getClass().getResource(get_class_name());
        dir_name = myURL.getPath();
        dir_name = myURL.getPath().replaceAll("%20", " ");
        dir_name = dir_name.substring(0, dir_name.lastIndexOf("/"));
        return dir_name;
    }

    public int get_ELO_init() {
        int ret = 0;
        ret = Integer.parseInt(dohProp.getProperty("ELO_init").trim());
        if (ret == 0) {
            ret = 1500;
        }
        return ret;
    }

    public int get_ELO_max_adj() {
        int ret = 0;
        ret = Integer.parseInt(dohProp.getProperty("ELO_max_adj").trim());
        if (ret == 0) {
            ret = 32;
        }
        return ret;
    }

    public int get_num_rounds() {
        int ret = 0;
        ret = Integer.parseInt(dohProp.getProperty("num_rounds").trim());
        if (ret == 0) {
            ret = 3;
        }
        return ret;
    }
    
    public long get_timeout(){
        return Integer.parseInt(dohProp.getProperty("timeout").trim()) * 1000;
    }
}
